home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / scd113.arc / DEMO2.C < prev    next >
C/C++ Source or Header  |  1990-06-14  |  4KB  |  121 lines

  1. /*************************************************
  2.  **                                             **
  3.  **   demo2.c                                   **
  4.  **                                             **
  5.  **     SoftC (tm) Dbase Library                **
  6.  **       Diskette TOC Demo Program             **
  7.  **                                             **
  8.  **           Copyright (C) 1989 by             **
  9.  **               Kim Schumann                  **
  10.  **               16820 3rd St NE               **
  11.  **               Ham Lake, MN 55304            **
  12.  **               (612) 434-6968                **
  13.  **                                             **
  14.  **             All rights reserved.            **
  15.  *************************************************/
  16.  
  17.  
  18. /*
  19.           The Diskette  TOC Program is a simple program which will create a
  20.           database (TOC.DBF)  and three  index files.  The database  record
  21.           contains the following fields:
  22.  
  23.  
  24.           field name     type length    description
  25.           ----------     ---- ------    -----------
  26.           NAME            C    12       file name
  27.           LENGTH          N    10.0     file size in bytes
  28.           DATE            D     8       file creation date
  29.           TIME            C     8       file creation time
  30.           ATTRIBUTE       C     3       file attribute (READ ONLY, HIDDEN)
  31.  
  32.  
  33.           The  index   files  created   are:   TOCNAME.NDX   (file   name),
  34.           TOCLNGTH.NDX (file  length), and  TOCDATE.NDX (file creation date
  35.           and time).
  36.  
  37.  
  38.           The program  uses the DOS functions "findfirst" and "findnext" to
  39.           step through  the  files  in  the  directory.  It  reformats  the
  40.           compressed file  date  ("mm/dd/yy")  and  time  ("hh:mm:ss")  and
  41.           places the  resultant data  into the  output  buffer.  After  all
  42.           fields have  been entered  it will  append a record to the end of
  43.           the database and add keys for each file found.
  44.  
  45.  
  46.           The program  only works  on the  current directory.  It does  not
  47.           support any command line arguments, although it would be easy for
  48.           the user  to add  such support.  Very little  error  checking  is
  49.           performed.
  50.  
  51.  
  52.           The program  as it  stands has value only in the demonstration of
  53.           certain library  functions. However, it could form the basis of a
  54.           diskette cataloger, or ...
  55.  
  56. */
  57.  
  58.  
  59. #include <stdlib.h>
  60. #include <dir.h>
  61. #include <stdio.h>
  62. #include <string.h>
  63. #include <sc_base.h>
  64.  
  65. SC_FIELD fields[] = { "name",'c',64,0,
  66.                       "length",'n',10,0,
  67.                       "date",'d',8,0,
  68.                       "time",'c',8,0,
  69.                       "attribute",'n',3,0 };
  70.  
  71. void main ()
  72. {
  73.   struct ffblk ffblk;
  74.   int r, w1, w2, w3;
  75.   char dbf, ndx1, ndx2, ndx3, work[9], *key;
  76.   long recno;
  77.   double d;
  78.  
  79.   scdinit(20);
  80.   scddcreate("toc.dbf",5,fields);
  81.   scddopen(&dbf,"toc.dbf");
  82.   scdncreate("tocname.ndx",'c',"name",64);
  83.   scdnopen(&ndx1,"tocname.ndx");
  84.   scdncreate("toclngth.ndx",'n',"length",64);
  85.   scdnopen(&ndx2,"toclngth.ndx");
  86.   scdncreate("tocdate.ndx",'c',"dtoc(date) + time",64);
  87.   scdnopen(&ndx3,"tocdate.ndx");
  88.   findfirst("*.*",&ffblk,0);
  89.   do {
  90.     scdfput(dbf,0,ffblk.ff_name);
  91.     d = (double) ffblk.ff_fsize;
  92.     scdfput(dbf,1,&d);
  93.     w1 = ((ffblk.ff_fdate & 0xFE00) >> 9) + 80;
  94.     w2 = (ffblk.ff_fdate & 0x01E0) >> 5;
  95.     w3 = ffblk.ff_fdate & 0x001F;
  96.     sprintf(work,"%02d/%02d/%02d",w2,w3,w1);
  97.     scdfput(dbf,2,work);
  98.     w1 = (ffblk.ff_ftime & 0xF800) >> 11;
  99.     w2 = (ffblk.ff_ftime & 0x07E0) >> 5;
  100.     w3 = (ffblk.ff_ftime & 0x001F) << 1;
  101.     sprintf(work,"%02d:%02d:%02d",w1,w2,w3);
  102.     scdfput(dbf,3,work);
  103.     d = (double) ffblk.ff_attrib;
  104.     scdfput(dbf,4,&d);
  105.     scdrput(dbf,&recno,SC_ADD);
  106.     if (sc_code == SC_SUCCESS)
  107.       scdkadd(ndx1,ffblk.ff_name,recno);
  108.       d = (double) ffblk.ff_fsize;
  109.       scdkadd(ndx2,(char *) &(d),recno);
  110.       scdkmake(dbf,ndx3,(void **) &key);
  111.       scdkadd(ndx3,key,recno);
  112.       free(key);
  113.     puts(ffblk.ff_name);
  114.     r = findnext(&ffblk);
  115.   } while (r != -1);
  116.   scddclose(dbf);
  117.   scdnclose(ndx1);
  118.   scdnclose(ndx2);
  119.   scdnclose(ndx3);
  120.   scdterm();
  121. }